package wdevent

import (
	"errors"
	"time"
)

func Timeout(to time.Duration, fn func() error) error {
	echan := make(chan error)
	go func() {
		err := fn()
		echan <- err
	}()
	select {
	case err := <-echan:
		return err
	case <-time.After(to):
		return errors.New("Timeout")
	}
}
